home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kurlrequester.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  8.7 KB  |  302 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1999,2000,2001 Carsten Pfeiffer <pfeiffer@kde.org>
  3.  
  4.     library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License version 2, as published by the Free Software Foundation.
  7.  
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU Library General Public License
  14.     along with this library; see the file COPYING.LIB.  If not, write to
  15.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.     Boston, MA 02110-1301, USA.
  17. */
  18.  
  19.  
  20. #ifndef KURLREQUESTER_H
  21. #define KURLREQUESTER_H
  22.  
  23. #include <qhbox.h>
  24.  
  25. #include <keditlistbox.h>
  26. #include <kfile.h>
  27. #include <kpushbutton.h>
  28. #include <kurl.h>
  29.  
  30. class KComboBox;
  31. class KFileDialog;
  32. class KLineEdit;
  33. class KURLCompletion;
  34. class KURLDragPushButton;
  35.  
  36. class QString;
  37. class QTimer;
  38.  
  39. /**
  40.  * This class is a widget showing a lineedit and a button, which invokes a
  41.  * filedialog. File name completion is available in the lineedit.
  42.  *
  43.  * The defaults for the filedialog are to ask for one existing local file, i.e.
  44.  * KFileDialog::setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly )
  45.  * The default filter is "*", i.e. show all files, and the start directory is
  46.  * the current working directory, or the last directory where a file has been
  47.  * selected.
  48.  *
  49.  * You can change this behavior by using setMode() or setFilter().
  50.  *
  51.  * \image html kurlrequester.png "KDE URL Requester"
  52.  *
  53.  * @short A widget to request a filename/url from the user
  54.  * @author Carsten Pfeiffer <pfeiffer@kde.org>
  55.  */
  56. class KIO_EXPORT KURLRequester : public QHBox
  57. {
  58.     Q_OBJECT
  59.     Q_PROPERTY( QString url READ url WRITE setURL )
  60.     Q_PROPERTY( bool showLocalProtocol READ showLocalProtocol WRITE setShowLocalProtocol )
  61.     Q_PROPERTY( QString filter READ filter WRITE setFilter )
  62.     Q_PROPERTY( uint mode READ mode WRITE setMode )
  63.  
  64. public:
  65.     /**
  66.      * Constructs a KURLRequester widget.
  67.      */
  68.     KURLRequester( QWidget *parent=0, const char *name=0 );
  69.  
  70.     /**
  71.      * Constructs a KURLRequester widget with the initial URL @p url.
  72.      * // TODO KDE4: Use KURL instead
  73.      */
  74.     KURLRequester( const QString& url, QWidget *parent=0, const char *name=0 );
  75.  
  76.     /**
  77.      * Special constructor, which creates a KURLRequester widget with a custom
  78.      * edit-widget. The edit-widget can be either a KComboBox or a KLineEdit
  79.      * (or inherited thereof). Note: for geometry management reasons, the
  80.      * edit-widget is reparented to have the KURLRequester as parent.
  81.      */
  82.     KURLRequester( QWidget *editWidget, QWidget *parent, const char *name=0 );
  83.     /**
  84.      * Destructs the KURLRequester.
  85.      */
  86.     ~KURLRequester();
  87.  
  88.     /**
  89.      * @returns the current url in the lineedit. May be malformed, if the user
  90.      * entered something weird. ~user or environment variables are substituted
  91.      * for local files.
  92.      * // TODO KDE4: Use KURL so that the result is properly defined
  93.      */
  94.     QString url() const;
  95.  
  96.     /**
  97.      * Enables/disables showing file:/ in the lineedit, when a local file has
  98.      * been selected in the filedialog or was set via setURL().
  99.      * Default is false, not showing file:/
  100.      * @see showLocalProtocol
  101.      */
  102.     void setShowLocalProtocol( bool b );
  103.  
  104.     /**
  105.      * Sets the mode of the file dialog.
  106.      * Note: you can only select one file with the filedialog,
  107.      * so KFile::Files doesn't make much sense.
  108.      * @see KFileDialog::setMode()
  109.      */
  110.     void setMode( uint m );
  111.  
  112.     /**
  113.     * Returns the current mode
  114.     * @see KFileDialog::mode()
  115.     * @since 3.3
  116.     */
  117.     uint mode() const;
  118.  
  119.  
  120.     /**
  121.      * Sets the filter for the file dialog.
  122.      * @see KFileDialog::setFilter()
  123.      */
  124.     void setFilter( const QString& filter );
  125.  
  126.     /**
  127.     * Returns the current filter for the file dialog.
  128.     * @see KFileDialog::filter()
  129.     * @since 3.3
  130.     */
  131.     QString filter() const;
  132.  
  133.     /**
  134.      * @returns whether local files will be prefixed with file:/ in the
  135.      * lineedit
  136.      * @see setShowLocalProtocol
  137.      */
  138.     bool showLocalProtocol() const { return myShowLocalProt; }
  139.     // ## KDE4: there's no reason to keep this, it should always be false
  140.  
  141.     /**
  142.      * @returns a pointer to the filedialog
  143.      * You can use this to customize the dialog, e.g. to specify a filter.
  144.      * Never returns 0L.
  145.      *
  146.      * Remove in KDE4? KURLRequester should use KDirSelectDialog for
  147.      * (mode & KFile::Directory) && !(mode & KFile::File)
  148.      */
  149.     virtual KFileDialog * fileDialog() const;
  150.  
  151.     /**
  152.      * @returns a pointer to the lineedit, either the default one, or the
  153.      * special one, if you used the special constructor.
  154.      *
  155.      * It is provided so that you can e.g. set an own completion object
  156.      * (e.g. KShellCompletion) into it.
  157.      */
  158.     KLineEdit * lineEdit() const;
  159.  
  160.     /**
  161.      * @returns a pointer to the combobox, in case you have set one using the
  162.      * special constructor. Returns 0L otherwise.
  163.      */
  164.     KComboBox * comboBox() const;
  165.  
  166.     /**
  167.      * @returns a pointer to the pushbutton. It is provided so that you can
  168.      * specify an own pixmap or a text, if you really need to.
  169.      */
  170.     KPushButton * button() const;
  171.  
  172.     /**
  173.      * @returns the KURLCompletion object used in the lineedit/combobox.
  174.      */
  175.     KURLCompletion *completionObject() const { return myCompletion; }
  176.  
  177.     /**
  178.      * @returns an object, suitable for use with KEditListBox. It allows you
  179.      * to put this KURLRequester into a KEditListBox.
  180.      * Basically, do it like this:
  181.      * \code
  182.      * KURLRequester *req = new KURLRequester( someWidget );
  183.      * [...]
  184.      * KEditListBox *editListBox = new KEditListBox( i18n("Some Title"), req->customEditor(), someWidget );
  185.      * \endcode
  186.      * @since 3.1
  187.      */
  188.     KEditListBox::CustomEditor customEditor();
  189.  
  190. public slots:
  191.     /**
  192.      * Sets the url in the lineedit to @p url. Depending on the state of
  193.      * showLocalProtocol(), file:/ on local files will be shown or not.
  194.      * @since 3.1
  195.      * // TODO KDE4: Use KURL instead
  196.      */
  197.     void setURL( const QString& url );
  198.  
  199.     /**
  200.      * Sets the url in the lineedit to @p url.
  201.      * @since 3.4
  202.      * // TODO KDE4: rename to setURL
  203.      */
  204.     void setKURL( const KURL& url );
  205.  
  206.     /**
  207.      * Sets the caption of the file dialog.
  208.      * @since 3.1
  209.      */
  210.     virtual void setCaption( const QString& caption );
  211.  
  212.     /**
  213.      * Clears the lineedit/combobox.
  214.      */
  215.     void clear();
  216.  
  217. signals:
  218.     // forwards from LineEdit
  219.     /**
  220.      * Emitted when the text in the lineedit changes.
  221.      * The parameter contains the contents of the lineedit.
  222.      * @since 3.1
  223.      */
  224.     void textChanged( const QString& );
  225.  
  226.     /**
  227.      * Emitted when return or enter was pressed in the lineedit.
  228.      */
  229.     void returnPressed();
  230.  
  231.     /**
  232.      * Emitted when return or enter was pressed in the lineedit.
  233.      * The parameter contains the contents of the lineedit.
  234.      */
  235.     void returnPressed( const QString& );
  236.  
  237.     /**
  238.      * Emitted before the filedialog is going to open. Connect
  239.      * to this signal to "configure" the filedialog, e.g. set the
  240.      * filefilter, the mode, a preview-widget, etc. It's usually
  241.      * not necessary to set a URL for the filedialog, as it will
  242.      * get set properly from the editfield contents.
  243.      *
  244.      * If you use multiple KURLRequesters, you can connect all of them
  245.      * to the same slot and use the given KURLRequester pointer to know
  246.      * which one is going to open.
  247.      */
  248.     void openFileDialog( KURLRequester * );
  249.  
  250.     /**
  251.      * Emitted when the user changed the URL via the file dialog.
  252.      * The parameter contains the contents of the lineedit.
  253.      * // TODO KDE4: Use KURL instead
  254.      */
  255.     void urlSelected( const QString& );
  256.  
  257. protected:
  258.     void        init();
  259.  
  260.     KURLCompletion *    myCompletion;
  261.  
  262.  
  263. private:
  264.     KURLDragPushButton * myButton;
  265.     bool         myShowLocalProt;
  266.     mutable KFileDialog * myFileDialog;
  267.  
  268.  
  269. protected slots:
  270.     /**
  271.      * Called when the button is pressed to open the filedialog.
  272.      * Also called when KStdAccel::Open (default is Ctrl-O) is pressed.
  273.      */
  274.     void slotOpenDialog();
  275.  
  276. private slots:
  277.     void slotUpdateURL();
  278.  
  279. protected:
  280.     virtual void virtual_hook( int id, void* data );
  281.     bool eventFilter( QObject *obj, QEvent *ev );
  282. private:
  283.     class KURLRequesterPrivate;
  284.     KURLRequesterPrivate *d;
  285. };
  286.  
  287. /**
  288.  * URL requester with a combo box, for use in Designer
  289.  */
  290. class KIO_EXPORT KURLComboRequester : public KURLRequester
  291. {
  292.     Q_OBJECT
  293. public:
  294.     /**
  295.      * Constructs a KURLRequester widget with a combobox.
  296.      */
  297.     KURLComboRequester( QWidget *parent=0, const char *name=0 );
  298. };
  299.  
  300.  
  301. #endif // KURLREQUESTER_H
  302.